﻿using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput.Enum;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartWMS.Common.ResponseOutput
{
    public class Response<T>
    {
        public string? Message { set; get; }

        public ResponseEnum Code { set; get; }

        public T? Data { set; get; }

        public int TotalCount { set; get; }

        public int PageCount { get; set; }

        /// <summary>
        /// 分页方法
        /// </summary>
        /// <param name="data">集合</param>
        /// <param name="totalCount">数据总条数</param>
        /// <param name="pageCount">数据总页数</param>
        /// <returns>返回匿名对象</returns>
        public static Response<T> Ok(T data, int totalCount, int pageCount)
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Success,
                Data = data,
                TotalCount = totalCount,
                PageCount = pageCount

            };
        }

		public static Response<T> Ok(T data, int totalCount=1, string? message="")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Success,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.Success.GetDescription() : message,
                Data = data,
                TotalCount = totalCount,

            };
        }

        public static Response<T> Fail(T data)
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Fail,
                Message = ResponseEnum.Fail.GetDescription(),
                Data = data
            };
        }

        public static Response<T> Fail(string message = "")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.Fail,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.Fail.GetDescription() : message,
            };
        }

        public static Response<T> SystemError(string message = "")
        {
            return new Response<T>()
            {
                Code = ResponseEnum.SystemError,
                Message = string.IsNullOrEmpty(message) ? ResponseEnum.SystemError.GetDescription() : message,
            };
        }

    }
}
